package com.touwowo.five;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.touwowo.utils.RabbitMqUtils;

public class ReceiveLogs1 {
    //申明交换机名称
    private static final String EXCHANGE_NAME = "log";

    public static void main(String[] args) throws Exception{
        Channel channel = RabbitMqUtils.getChannel();
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.FANOUT);
        /*
         * 生成一个临时的队列 队列的名称是随机的
         * 当消费者断开和该队列的连接时 队列自动删除
         */
        String queue = channel.queueDeclare().getQueue();
        // 绑定临时队列到交换机
        channel.queueBind(queue,EXCHANGE_NAME,"");
        DeliverCallback deliverCallback = (consumerTag, message) -> {
            System.out.println("工作线程1收到的消息为："+new String(message.getBody()));
        };
        channel.basicConsume(queue,true,deliverCallback,(consumerTag -> {}));
    }
}
